package com.shrct.businessprocess.money;

import com.google.common.base.Objects;
import com.shrct.businessprocess.project.RCExchangeRate;
import com.shrct.businessprocess.project.RCProjectMoney;
import java.util.Collection;
import org.eclipse.xtext.xbase.lib.Functions.Function2;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

@SuppressWarnings("all")
public class MoneyExtensions {
  public RCProjectMoney sum(final Collection<RCProjectMoney> aLotOfMoney, final RCExchangeRate exchangeRate) {
    RCProjectMoney _xblockexpression = null;
    {
      final Function2<RCProjectMoney,RCProjectMoney,RCProjectMoney> _function = new Function2<RCProjectMoney,RCProjectMoney,RCProjectMoney>() {
          public RCProjectMoney apply(final RCProjectMoney m1, final RCProjectMoney m2) {
            RCProjectMoney _plus = m1.plus(m2);
            return _plus;
          }
        };
      RCProjectMoney result = IterableExtensions.<RCProjectMoney>reduce(aLotOfMoney, _function);
      RCProjectMoney _xifexpression = null;
      boolean _equals = Objects.equal(result, null);
      if (_equals) {
        RCProjectMoney _rCProjectMoney = new RCProjectMoney();
        final Procedure1<RCProjectMoney> _function_1 = new Procedure1<RCProjectMoney>() {
            public void apply(final RCProjectMoney it) {
              it.setAmount(Double.valueOf(0d));
              it.setExchange(exchangeRate);
            }
          };
        RCProjectMoney _doubleArrow = ObjectExtensions.<RCProjectMoney>operator_doubleArrow(_rCProjectMoney, _function_1);
        _xifexpression = _doubleArrow;
      } else {
        RCProjectMoney _money = result.toMoney(exchangeRate);
        _xifexpression = _money;
      }
      _xblockexpression = (_xifexpression);
    }
    return _xblockexpression;
  }
}
